package hunterxhunter.greedisland.data;

import java.awt.Rectangle;
import java.util.Arrays;
import java.util.LinkedList;

/**
 *
 * @author Markus Schr&ouml;der
 */
public class AnimationSequence extends LinkedList<Rectangle> {

    private String imageRef;
    
    private int current;
    private boolean spin = true;
    
    public AnimationSequence(String imageRef) {
        this.imageRef = imageRef;
    }
    
    public AnimationSequence(String imageRef, Rectangle... srcs) {
        this(imageRef);
        addAll(Arrays.asList(srcs));
    }
    
    public void reset() {
        this.setCurrent(0);
    }
    
    public void inc() {
        setCurrent(getCurrent() + 1);
        if(getCurrent() >= size()){
            if(spin)
                setCurrent(0);
            else
                setCurrent(size()-1);
        }
    }
    
    public void dec() {
        setCurrent(getCurrent() - 1);
        if(getCurrent() < 0) {
            if(spin)
                setCurrent(size()-1);
            else
                setCurrent(0);
        }
    }
    
    public Rectangle getCurrentRect() {
        return get(getCurrent());
    }

    /**
     * @return the imageRef
     */
    public String getImageRef() {
        return imageRef;
    }

    /**
     * @param imageRef the imageRef to set
     */
    public void setImageRef(String imageRef) {
        this.imageRef = imageRef;
    }

    /**
     * @return the current
     */
    public int getCurrent() {
        return current;
    }

    /**
     * @param current the current to set
     */
    public void setCurrent(int current) {
        this.current = current;
    }
}
